﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EVM.Implementation;

namespace ARSys.Web
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnTestGetACIModel_Click(object sender, EventArgs e)
        {
            var aco = new Business().GetACIModel();
            lblTestRender.Text = HttpUtility.HtmlEncode(aco.XML);
        }

        protected void btnTestGetUserACI_Click(object sender, EventArgs e)
        {
            var aco = new Business().GetUserACI(new IAM.Interface.Model.AccountInfo
            {
                AppAccount = "5", //冯大慈
            });
            lblTestRender.Text = HttpUtility.HtmlEncode(aco.XML);
        }

        protected void btnTestSetUserACI_Click(object sender, EventArgs e)
        {
            var sessions = new IAM.Interface.Model.ACISessions();

            foreach (var role in new string[] { "Architecture Manager", "Configuration Manager" })
            {
                var session = new IAM.Interface.Model.ACISession();
                var item = new IAM.Interface.Model.CheckedItem();
                item.ACItemID = role;
                item.Value = true;
                session.Items.Add(item);
                sessions.Items.Add(session);
            }

            var aco = new Business().SetUserACI(new IAM.Interface.Model.ACI
            {
                AccountInfo = new IAM.Interface.Model.AccountInfo
                {
                    AppAccount = "5", //冯大慈
                },
                ACISessions = sessions,
            });
            lblTestRender.Text = HttpUtility.HtmlEncode(aco.XML);
        }

        protected void btnTestGenerateAllUserACI_Click(object sender, EventArgs e)
        {
            string path = ConfigurationManager.AppSettings["IAMOutput"];

            var s = new Business().GenerateAllUserACI();
            File.WriteAllText(path, s);
            lblTestRender.Text = "File was generated at " + path;
        }
    }
}